<template>
  <div id="data-box">
    <div class="data-div1">
      <el-table
          :data="tableData"
          style="width: 100%"
          :row-class-name="tableRowClassName">
        <el-table-column
            show-overflow-tooltip
            prop="area"
            label="区">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="site"
            label="地址">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="price"
            label="价格">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="title"
            label="标题">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="lease"
            label="租凭方式">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="size"
            label="房屋大小">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="m"
            label="面积">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="orien"
            label="朝向">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="maintain"
            label="维护">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="checkIn"
            label="入住">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="floor"
            label="楼层">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="lift"
            label="电梯">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="stall"
            label="车位">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="water"
            label="用水">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="electro"
            label="用电">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="fuel"
            label="燃气">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="heating"
            label="采暖">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="tenan"
            label="租期">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="long"
            label="经度">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="dim"
            label="维度">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="url1"
            label="详情页">
          <template slot-scope="scope">
            <a :href="scope.row.url1">房屋详情</a>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="data-div2" v-show="tableData.length > 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage1"
          :page-sizes="[16, 32, 64, 128]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total=pageCount>
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DataManagement',
  data() {
    return {
      pageSize: 16,
      pageCount: 0,
      currentPage1: 1,
      tableData: []
    }
  },
  mounted() {
    this.getPageCount();
    this.getDataAll(0, this.pageSize);
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row' + row;
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    //  分页
    handleSizeChange(val) {
      this.pageSize = val;   // 没有分页数
    },
    handleCurrentChange(val) {
      this.tableData = [];
      let start = (val - 1) * this.pageSize;
      this.getDataAll(start, this.pageSize)

    },
    getPageCount() {
      this.$axios.get('/api/vis/getData17', {}).then(res => {
        if (res.data.code === 20041) {
          this.pageCount = res.data.data;
        }
      }).catch(error => {
        this.open4(error);
      })
    },
    getDataAll(start, end) {
      this.$axios.post('/api/vis/getData18', {
          "start": start,
          "end": end
      }).then(res => {
        if (res.data.code === 20041) {
          this.tableData = [];
          for (let i = 0; i < res.data.data.length; i++) {
            this.tableData.push(
                {
                  area: res.data.data[i].param1,
                  site: res.data.data[i].param2,
                  price: res.data.data[i].param3,
                  title: res.data.data[i].param4,
                  lease: res.data.data[i].param5,
                  size: res.data.data[i].param6,
                  m: res.data.data[i].param7,
                  orien: res.data.data[i].param8,
                  maintain: res.data.data[i].param9,
                  checkIn: res.data.data[i].param10,
                  floor: res.data.data[i].param11,
                  lift: res.data.data[i].param12,
                  stall: res.data.data[i].param13,
                  water: res.data.data[i].param14,
                  electro: res.data.data[i].param15,
                  fuel: res.data.data[i].param16,
                  heating: res.data.data[i].param17,
                  tenan: res.data.data[i].param18,
                  long: res.data.data[i].param19,
                  dim: res.data.data[i].param20,
                  url1: res.data.data[i].param21,
                }
            )
          }
        }
      }).catch(error => {
        this.open4(error);
      })
    }
  }
}
</script>

<style scoped>

  #data-box {
    height: 100%;
    width: 100%;
    .el-table .warning-row {
      background: oldlace;
    }

    .el-table .success-row {
      background: #f0f9eb;
    }
    overflow-x: hidden;
    overflow-y: auto;
  }
  #data-box .data-div1 {
    width: 100%;
    margin: auto;
  }
  #data-box .data-div2 {
    width: 40%;
    margin: auto;
  }

</style>